#!/usr/bin/env python3
"""
验证 torch.Size 错误修复

快速验证是否修复了 TypeError: '>' not supported between instances of 'torch.Size' and 'int'
"""

import sys
import os
import numpy as np

# 添加项目根目录到路径
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

def main():
    """主验证函数"""
    print("验证 torch.Size 错误修复...")
    
    try:
        from kidsbuddy.vision.attention_detector import AttentionDetector
        
        # 初始化检测器
        detector = AttentionDetector()
        
        # 创建测试图像
        test_frame = np.random.randint(0, 255, (480, 640, 3), dtype=np.uint8)
        
        # 这里之前会出现 torch.Size 比较错误
        print("执行 process_frame...")
        status, reasons, keypoints_data, features = detector.process_frame(test_frame)
        
        print("✅ 成功！没有出现 torch.Size 错误")
        print(f"状态: {status}")
        print(f"原因数量: {len(reasons)}")
        
        return True
        
    except TypeError as e:
        if "torch.Size" in str(e) and "not supported between instances" in str(e):
            print(f"❌ torch.Size 错误仍然存在: {e}")
            return False
        else:
            print(f"⚠️  其他 TypeError: {e}")
            return True  # 不是我们要修复的错误
            
    except Exception as e:
        print(f"⚠️  其他错误: {e}")
        return True  # 不是我们要修复的错误

if __name__ == "__main__":
    success = main()
    if success:
        print("\n🎉 修复验证成功！可以正常使用注意力检测器了。")
    else:
        print("\n❌ 修复验证失败！需要进一步检查。")
    sys.exit(0 if success else 1)
